@extends('develop.layoutEdit')

@section('title')
    @if(isset($style['id']) && $style['id']>0)
        <li class="cur">
            <span>修改样式库 </span>
        </li>
    @else
        <li class="cur">
            <span>添加样式库 </span>
        </li>
    @endif
@endsection

@section('content')

    <div class="form-group">
        <label class="col-sm-3 control-label"><span class="red pr5">*&nbsp;</span>所属模块：</label>
        <div class="col-sm-3">
            <select class="form-control" name="module_name" id="module_name" @if( $remark == 2)disabled="true" @endif>
                <option value="">请选择</option>
                @if ( isset( $style_data ) && !empty( $style_data ) )
                    @foreach( $style_data as $item )
                        @if ( isset($style) && !empty($style) && $style['module_id'] == $item['id'])
                            <option value="{{$item['id']}}" selected>{{$item['module_name']}}</option>
                        @elseif(isset($module_array) && !empty($module_array) && $module_array['id'] == $item['id'])
                            <option value="{{$item['id']}}" selected >{{$item['module_name']}}</option>
                        @else
                            <option value="{{$item['id']}}">{{$item['module_name']}}</option>
                        @endif
                    @endforeach
                @endif
            </select>
        </div>
    </div>

    <div class="form-group">
        <label class="col-sm-3 control-label"><span class="red mr5">*&nbsp;</span>样式库名称：</label>
        <div class="col-sm-3">
            <input type="text" class="form-control"  name="style_name" id="style_name" placeholder="请输入默认样式库名称" value="{{ $style['style_name'] or ''}}">
        </div>
    </div>

    <div class="form-group ">
        <label class="col-sm-3 control-label"><span class="red pr5">*&nbsp;</span>样式库CSS：</label>
        <div class="col-sm-5">
            <textarea name="style_css" class="form-control"  rows="10"  id="style_css" placeholder="请输入样式库css代码">{{ $style['style_css'] or ''}}</textarea>
        </div>
    </div>

    <div class="form-group" id="edit">
        <label class="col-sm-3 control-label"></label>
        <div class="col-sm-9">
            <input type="hidden" name="id" id="id" value="{{ $id or ''}}">
            <input type="button"  value="保存" onclick="Module.edit();" class="btn btn-success" >
        </div>
    </div>

@endsection

@section('js')
    <script>

        //按钮入口标识 0.样式库列表添加按钮 1.样式库列表修改按钮 2.模块列表添加样式库按钮
        var remark ={{$remark or ''}};

        var Module = {

            //保存
            edit:function () {
                $("#module_name").attr("disabled",false);
                var data = E.getFormValues('edit-form');

                var message ='';
                if (E.isEmpty(data.module_name) ) {
                    message += '请选择所属模块</br>';
                }

                if (E.isEmpty(data.style_name) ) {
                    message += '请输入默认样式库名称</br>';
                }

                if (E.isEmpty(data.style_css) ) {
                    message += '请输入样式库css代码</br>';
                }

                if ( message ) {
                    layer.alert(message,{icon:2});
                    return false;
                }

                if ( data.id && data.id>0 && remark==1) {
                    var t = '您确认要修改该样式信息吗';
                } else {
                    var t = '您确认要添加该样式信息吗';
                }

                layer.confirm(t,{icon:3},function(index){

                    layer.close(index);
                    E.ajax({
                        type:'get',
                        url: '/lar/develop/module/style/store',
                        data: data,
                        dataType:'json',
                        // 返回值判断
                        success: function (obj) {
                            if ( obj.code == 200 ) {
                                layer.alert( obj.message , { icon: 1,time : 1500 } ) ;
                                parent.Module.load();
                                setTimeout('E.layerClose();' ,1000 );
                            } else {
                                layer.alert(obj.message, {icon: 2});
                            }

                        }
                    });
                });

            }
        };


    </script>
@endsection